package medium前缀树;

import java.util.*;

public class Trie {

    private Set<String> list;
    public Trie() {
        list = new HashSet<>();
    }

    public void insert(String word) {
        list.add(word);
    }

    public boolean search(String word) {
        return list.contains(word);
    }

    public boolean startsWith(String prefix) {
        Iterator<String> iterator = list.iterator();
        while(iterator.hasNext()){
            if (iterator.next().startsWith(prefix))
                return true;
        }
        return false;
    }
}
